#include <fstream>
#include "log_writer.h"
using namespace std;

namespace andrew::tools::conf
{
	conf::conf()
	{

	}
	conf::~conf()
	{
		clear();
		obj_log_writer.close();
	}
	int conf::init(const char* _tmp_conf_file)
	{
		return OK;
	}
	int conf::load_conf(const char* _tmp_load_file)
	{
		if(NULL == _tpm_load_file)
		{
			obj_log_writer.;
			return ERROR;
		}	
		ofstream _file_reader;
		_file_reader.open(_tmp_load_file,ios_base::out);//read
		if(!_file_reader.is_open())
		{
			return ERROR;
		}
		string _key,_value;

		unsigned int _cnt = 0;
		while(_file_reader>>_key)
		{
			if(_key.length() > 0 && _key[0] != '#')
			{
				if(_file_reader>>_value)
				{
					obj_map_key_value.push_back(make_pair<std::string,
							std::string>(_key,_value));
					_cnt ++;
				}
			}
		}
		_file_reader.close();
		return OK;
	}
	int conf::clear()
	{
		obj_map_key_value.clear();
		return OK;
	}
	int conf::getValue(const std::string &_key,std::string &_value)
	{
		map<string,string>::iterator _it;
		_it = obj_map_key_value.find(_key);
		_value = (_it == obj_map_key_value.end()) ? "" : _it->second;
		return OK;
	}
	int conf::isKeyExist(const std::string &_key,std::string &_value)
	{
		int _tmp_ret_value = KEY_NOT_EXIST;
		map<string,string>::iterator _it;
		_it = obj_map_key_value.find(_key);
		if(&_value != NULL)
			_value = (_it == obj_map_key_value.end()) ?
			       	"" :( _it->second,_tmp_ret_value = KEY_EXIST);
		else if(_it != obj_map_key_value.end())
			_tmp_ret_value = KEY_EXIST;
		return _tmp_ret_value;
	}
	inline
	int conf::getCount(int &_tmp_count)
	{
		_tmp_count = obj_map_key_value.size();

		return OK;
	}

}
